<%@ include file="/includes.jsp" %>
<%@ include file="/header.jsp" %>

<c:choose>
    <c:when test="${event.new}">
        <h2>Add Event</h2>
    </c:when>
    <c:otherwise>
        <h2>Update Event</h2>
    </c:otherwise>
</c:choose>


<form:form modelAttribute="event">
    <%--<form:hidden path="id"/>--%>
    <table>
        <tr>
            <td>Event Name:</td>
            <td><form:input path="name" size="30" maxlength="30"/></td>
            <td><form:errors path="name" cssClass="errors"/></td>
        </tr>
        <tr>
            <td>Event Description:</td>
            <td><form:textarea path="description" cols="30"/></td>
            <td><form:errors path="description" cssClass="errors"/></td>
        </tr>
        <tr>
            <td>Location:</td>
            <td><form:input path="location" size="30" maxlength="80"/></td>
            <td><form:errors path="location" cssClass="errors"/></td>
        </tr>
        <tr>
            <td>Start time:</td>
            <td><form:input path="startTime" size="20" maxlength="20"/> [MM.dd.yy HH:mm]</td>
            <td><form:errors path="startTime" cssClass="errors"/></td>
        </tr>
        <tr>
            <td>End time:</td>
            <td><form:input path="endTime" size="20" maxlength="20"/> [MM.dd.yy HH:mm]</td>
            <td><form:errors path="endTime" cssClass="errors"/></td>
        </tr>
        <tr>
            <td colspan="3">
                <c:choose>
                    <c:when test="${event.new}">
                        <p class="submit"><input type="submit" value="Add Event"/></p>
                    </c:when>
                    <c:otherwise>
                        <p class="submit"><input type="submit" value="Update Event"/></p>
                    </c:otherwise>
                </c:choose>
            </td>
        </tr>
    </table>
</form:form>

<c:choose>
    <c:when test="${event.new}">
        <%--<h2>Positions</h2>--%>
    </c:when>
    <c:otherwise>
        <h2>Positions for event: ${event.name}</h2>

        <table>
            <thead>
            <tr align="left">
                <th>Position</th>
                <th>Location</th>
                <th>Count</th>
                <th>Start Time</th>
                <th>End Time</th>
                <th>Volunteers</th>
                <th>Edit</th>
                <th>Delete</th>
            </tr>
            </thead>
            <c:if test="${empty event.positions}">
                <tr>
                    <td colspan="8">
                        No positions have volunteer opportunities.
                    </td>
                </tr>
            </c:if>
            <c:if test="${not empty event.positions}">
                <c:forEach var="position" items="${event.positions}">
                    <tr valign="top">
                        <td>
                            <a href="/controller/position/form?eventId=${event.id}&id=${position.id}">${position.name}</a>
                        </td>
                        <td>${position.location}</td>
                        <td>${position.count}</td>
                        <td>${position.startTime}</td>
                        <td>${position.endTime}</td>
                        <td>
                            <c:forEach var="volunteer" items="${position.volunteers}">
                                ${volunteer.firstName} ${volunteer.lastName}<br/>
                            </c:forEach>
                        </td>
                        <td>
                            <form method="GET" action="<c:url value="../position/form"/>" name="editPosition">
                                <input type="hidden" name="eventId" value="${event.id}"/>
                                <input type="hidden" name="id" value="${position.id}"/>
                                <input class="submit" type="submit" value="Edit"/>
                            </form>
                        </td>
                        <td>
                            <form method="GET" action="<c:url value="../position/delete"/>" name="deletePosition">
                                <input type="hidden" name="eventId" value="${event.id}"/>
                                <input type="hidden" name="id" value="${position.id}"/>
                                <input class="submit" type="submit" value="Delete"/>
                            </form>
                        </td>
                    </tr>
                </c:forEach>
            </c:if>
        </table>
        <p>
        <form method="GET" action="<c:url value="../position/form"/>" name="newPosition">
            <input type="hidden" name="eventId" value="${event.id}"/>
            <input class="submit" type="submit" value="Create New Positon"/>
        </form>
        </p>


    </c:otherwise>
</c:choose>


<%@ include file="../footer.jsp" %>